package com.zxj.flights.common.util;

import java.util.Random;

import org.springframework.stereotype.Component;

/**
 * 所有正则表达式的工具类
 *
 */
@Component("regexUtil")
public class RegexUtil
{
	private String souString = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ; 
	/**
	 * 生成随机数
	 * @return
	 */
	public String randStr(int length)
	{
		/* 存储所有的结果 */
		StringBuffer sb = new StringBuffer();
		Random random = new Random();
		for(int i = 0 ; i < length ; i ++ )
		{
			/* 生成20以内的随机数 (0-->19) */
			/* 生成随机字符串长度的下标值 */
			int res = random.nextInt(souString.length());
			char ch = souString.charAt(res);
			sb.append(ch);
		}
		return sb.toString() ; 
	}
	
	public static void main(String[] args)
	{
		RegexUtil regexUtil = new RegexUtil();
		String result = regexUtil.randStr(4);
		System.out.println(result);
	}
}
